package com.qf.base.controller;

import com.qf.base.domain.BaseCarrier;
import com.qf.base.service.IBaseCarrierService;
import com.qf.common.annotation.Log;
import com.qf.common.core.controller.BaseController;
import com.qf.common.core.domain.AjaxResult;
import com.qf.common.core.page.TableDataInfo;
import com.qf.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- ONE PIECE ---
 *
 * @author yangjiangcheng
 * @date 2025/9/2
 * @desc
 */
@RestController
@RequestMapping("/tms/base/carrier")
public class BaseCarrierController extends BaseController {

    @Autowired
    private IBaseCarrierService baseCarrierService;

    /**
     * 获取承运商信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseCarrier carrier) {
        startPage();
        List<BaseCarrier> list = baseCarrierService.selectCarrierList(carrier);
        return getDataTable(list);
    }

    /**
     * 新增承运商信息
     */
    @Log(title = "承运商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseCarrier carrier) {
        carrier.setCreateBy(getUsername());
        return toAjax(baseCarrierService.insertCarrier(carrier));
    }


    /**
     * 根据承运商Id获取详细信息
     */
    @GetMapping(value = "/{carrierId}")
    public AjaxResult getInfo(@PathVariable Long carrierId) {
        return success(baseCarrierService.selectCarrierById(carrierId));
    }


    /**
     * 修改承运商信息
     */
    @Log(title = "承运商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseCarrier carrier) {
        carrier.setUpdateBy(getUsername());
        return toAjax(baseCarrierService.updateCarrier(carrier));
    }


    /**
     * 删除承运商信息
     */
    @Log(title = "承运商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseCarrierService.deleteCarrierByIds(ids));
    }


}
